package com.yndsoft.jc.supplier.adapter;

import android.content.Context;
import android.view.View;

import com.yndsoft.jc.R;
import com.yndsoft.jc.supplier.model.OrderDetailModel.DetsBean;
import com.yndsoft.jc.supplier.order.entry.OrderEntryActivity;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerAdapter;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerHolder;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerListener;

import java.util.List;

public class EntryDetailAdapter extends RecyclerAdapter<DetsBean> implements RecyclerListener.OnClickListener<RecyclerHolder> {

    private String id;

    public EntryDetailAdapter(Context context, List<DetsBean> data, String id) {
        super(context, data, R.layout.item_entry_detail);
        this.id = id;
    }

    @Override
    public void convert(final RecyclerHolder holder, final DetsBean model) {
        DetsBean.ProductBean product = model.getProduct();
        if (product != null) {
            holder.setTvText(R.id.order_detail_title, product.getName() + product.getSubname());
        }
        DetsBean.ProductattributeBean productattribute = model.getProductattribute();
        if (productattribute != null) {
            holder.setTvText(R.id.order_detail_content, productattribute.getProject() + " | " + productattribute.getMethod() + " | " + productattribute.getStandard());
        }

        holder.setOnClickListener(this, R.id.order_detail_entry);
    }

    @Override
    public void onClick(View v, int position, RecyclerHolder holder) {
        switch (v.getId()) {
            case R.id.order_detail_entry:
                if (mData != null && mData.size() > 0) {
                    DetsBean detsBean = mData.get(position);
                    if (detsBean != null) {
                        OrderEntryActivity.start(mContext, id, detsBean.getId());
                    }
                }
                break;
        }
    }
}
